package com.yenlien.traceyun.control.service.rest;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.control.bean.RestURL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * Created by LiuSha on 2020/7/22.
 */
@Service
public class CompanyRestService {
    @Autowired
    private RestService restService;

    public Object findByList(JSONObject jsonObject) {
        return restService.postJson(RestURL.USERCENTER + "company/findByList", jsonObject);
    }

    public Object findFruitCompList(JSONObject jsonObject) {
        return restService.postJson(RestURL.USERCENTER + "company/findFruitCompList", jsonObject);
    }

    public Object findAllFruitCompList() {
        return restService.getJson(RestURL.USERCENTER + "company/findAllFruitCompList");
    }

    public Object findById(String id) {
        return restService.getJson(RestURL.USERCENTER + "company/findById/" + id);
    }

    public Object save(Map<String, Object> map, List<MultipartFile> files) {
        return restService.postForm(RestURL.USERCENTER + "company/save", map, files);
    }


    public Object updateInfo(JSONObject jsonObject) {
        return restService.postJson(RestURL.USERCENTER + "company/updateInfo", jsonObject);
    }

    public Object update(Map<String, Object> map, List<MultipartFile> files) {
        return restService.postForm(RestURL.USERCENTER + "company/update", map, files);
    }

    public Object update2(Map<String, Object> map) {
        return restService.postJson(RestURL.USERCENTER + "company/update2", map);
    }

    public Object delete(String id) {
        return restService.getJson(RestURL.USERCENTER + "company/delete/" + id);
    }

    /**
     * 配置政府权限
     *
     * @param map
     * @param files
     * @return
     */
    public Object setGovConfig(Map<String, Object> map, List<MultipartFile> files) {
        return restService.postForm(RestURL.USERCENTER + "company/gov/setcustomapp", map, files);
    }

    /**
     * 设置企业管理app
     *
     * @return
     */
    @RequestMapping(value = "/company/setcustomapp", method = RequestMethod.POST)
    public Object setCustomAppVersion(@RequestBody JSONArray array) throws Exception {
        return restService.postJson(RestURL.USERCENTER + "company/company/setcustomapp", array);
    }

    /**
     * 企业审核
     *
     * @param jsonObject
     * @return
     */
    public Object examined(JSONObject jsonObject) {
        return restService.postJson(RestURL.USERCENTER + "company/examined", jsonObject);
    }

    /**
     * 企业审核列表
     *
     * @return
     */
    public Object examinedlist(String companyId) {
        return restService.getJson(RestURL.USERCENTER + "company/examinedlist/" + companyId);
    }

    /**
     * 根据type加载企业
     *
     * @param type
     * @return
     */
    public Object companyType(String type) {
        return restService.getJson(RestURL.USERCENTER + "company/findByType/" + type);
    }

    /**
     * 获取企业已绑定的以应用
     *
     * @param companyId
     * @return
     */
    public Object getCustomApp(@PathVariable String companyId) {
        return restService.getJson(RestURL.USERCENTER + "company/get/customapp/" + companyId);
    }

    /**
     * 获取政府配置
     *
     * @return
     */
    public Object getGovConfig(String companyId) {
        return restService.getJson(RestURL.USERCENTER + "company/get/govconfig/" + companyId);
    }

    /**
     * 修改授权时间
     *
     * @return
     */
    public Object chenageExpiretime(JSONObject jsonObject) {
        return restService.postJson(RestURL.USERCENTER + "company/change/expiretime", jsonObject);
    }

    /**
     * 重置密码
     */
    public Object resetPassword(JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "company/resetpassword", param);
    }

    /**
     * 获取子企业
     *
     * @return
     */
    public Object getchild(String companyId) {
        return restService.getJson(RestURL.USERCENTER + "company/get/child/" + companyId);
    }

}
